<?php
namespace frontend\controllers;

use Yii;
use yii\web\Controller;
use frontend\models\Advertiser_info;

class BusinessController extends Controller{
	public $layout = 'min_business';
	public function actionIndex(){
		$session = Yii::$app->session;
		if($session->get('business')!=''){
			$advertiser_id = $session['business']['business_id'];
			// print_r($session['business']);die;
			$advertiser_info = new Advertiser_info;
			$data=$advertiser_info->getOne($advertiser_id);
			return $this->render('index',['data'=>$data,'advertiser_id'=>$session['business']['business_id']]);
		}else
		{
			$this->redirect('?w=businesslogin/index');
		}
	}
	public function actionSave(){
		$session = Yii::$app->session;
		$advertiser_info = new Advertiser_info;
		if($session->get('business')!=''){
			$advertiser_id = Yii::$app->session['business']['business_id'];
			$update = Yii::$app->request->post();
			if($update){
				// echo '<pre>';
				// print_r($update);
				$id = $update['id'];
				$Advertiser_info=Advertiser_info::findOne("$id");
				$Advertiser_info->company = $update['company'];
				$Advertiser_info->company_legal_person = $update['company_legal_person'];
				if($Advertiser_info->save()){
					$this->redirect(['index']);
				}
				return false;
			}
				$data=$advertiser_info->getOne($advertiser_id);
				return $this->render('save',['data'=>$data]);
		}
	}
}

?>